//获取当前年月日
function getDangQianRiQi() {
  return new Date();
}
//根据当前时间获取日期对象
function getRiQiObject(date, pd) {
  let riqi
  if (pd) { //pd有参数
    //根据年月日获得天数
    let d = new Date(date.nian, date.yue, 0).getDate()
    //获取第一天周几
    let week = new Date(date.nian, date.yue - 1, 1).getDay()
    let arr = getArrday(week, d)
    riqi = {
      nian: date.nian,
      yue: date.yue,
      ri: '',
      zhouji: week,
      dangqian: arr
    }
  } else { //pd没有参数
    // 获取当前年月日
    let day = date.getDate();
    // console.log(day);
    //0-11月的值
    let month = date.getMonth() + 1;
    let year = date.getFullYear();
    //根据年月日获取周几第一天周几
    let week = new Date(year, month - 1, 1).getDay()
    //获取当月多少天
    let days = new Date(year, month, 0).getDate()
    let arr = getArrday(week, days)
    riqi = {
      nian: year,
      yue: month,
      ri: day,
      zhouji: week,
      dangqian: arr
    }
  }
  return riqi
}
function formatDatetimexiegang(date) {
  function padZero(num) {
      return num < 10 ? '0' + num : num;
  }
  let year = date.getFullYear();
  let month = padZero(date.getMonth() + 1);
  let day = padZero(date.getDate());
  let hours = padZero(date.getHours());
  let minutes = padZero(date.getMinutes());
  let seconds = padZero(date.getSeconds());
  return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
}
function formatDatetime(date) {
  function padZero(num) {
      return num < 10 ? '0' + num : num;
  }
  let year = date.getFullYear();
  let month = padZero(date.getMonth() + 1);
  let day = padZero(date.getDate());
  let hours = padZero(date.getHours());
  let minutes = padZero(date.getMinutes());
  let seconds = padZero(date.getSeconds());
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
//根据天数渲染出数组对象
function getArrday(firstday, days) {
  //周三=3
  let arr = new Array();
  // console.log();
  for (let i = 1; i <= days; i++) {
    if (i <= firstday) {
      let riqiobject = {
        riqi_id: i,
        style: "0",
        emoimg_id: "0",
        emotext: "",
        list_id: ''
      }
      arr.push(riqiobject)
      arr.unshift(88)
    } else {
      let riqiobject = {
        riqi_id: i,
        style: "0",
        emoimg_id: "0",
        emotext: "",
        list_id: ''
      }
      arr.push(riqiobject)
    }
  }
  if (arr.length != 42) {
    let s = 42 - arr.length
    for (let i = 0; i < s; i++) {
      arr.push(88)
    }
  }
  return arr
}
//格式化时间没有几点
function formatDate(date) {
  let yyyy=date.nian;
  let mm = date.yue;
  let dd = date.ri;
  dd=dd.length==1?+dd:'0'+dd
 //  console.log(dd);
   return `${yyyy}-${mm}-${dd}`;
 }


module.exports = {
  getDangQianRiQi,
  getRiQiObject,
  formatDate,
  formatDatetime,
  formatDatetimexiegang
}

console.log(
  getRiQiObject(getDangQianRiQi())
);